<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:t="http://myfaces.apache.org/tomahawk" xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Gestão de Colaboradores</title>
    </h:head>
    <ui:decorate template="/tema/padrao.xhtml">
        <ui:define name="centro" >
            <t:saveState value="#{colaboradorBean.colaborador}" />
            <t:saveState value="#{colaboradorBean.colaboradores}" />
            <h:form id="form" >
                <p:panel header="Gestão de colaboradores" >
                    <p:fieldset legend="Consultar - Inserir" style="text-align: left">
                        <h:panelGrid columns="2">
                            <h:outputLabel value="Matrícula: " for="matricula" />
                            <p:inputText id="matricula" for="matricula" value="#{colaboradorBean.matriculaConsulta}"  maxlength="80" size="50"/>
                            <h:outputLabel value="Nome: " for="nome" />
                            <p:inputText id="nome" for="nome" value="#{colaboradorBean.nomeConsulta}"/>

                            <p:commandButton value="Consultar" actionListener="#{colaboradorBean.consultar}" update="tabela" />
                            <p:commandButton value="Inserir" action="#{colaboradorBean.novo}" ajax="false" />
                        </h:panelGrid>
                    </p:fieldset> 
                    <br/>
                    <p:dataTable id="tabela" value="#{colaboradorBean.colaboradores}" var="c"  rows="10" paginator="true" 
                                 emptyMessage="Nehum registro encontrado, ou consulta não efetuada. Clique em consultar." >
                        <f:facet name="header">  
                            Lista de Colaboradores
                        </f:facet> 
                        <p:column headerText="Matrícula" >
                            <h:outputText value="#{c.matricula}" />
                        </p:column>
                        <p:column headerText="Nome" >
                            <h:outputText value="#{c.nome}"/>
                        </p:column>
                        <p:column headerText="Cargo" >
                            <h:outputText value="#{c.cargo}"  />
                        </p:column>
                        <p:column headerText="Editar" >
                            <p:commandButton value="Editar" action="#{colaboradorBean.editar}" ajax="false" >
                                <f:setPropertyActionListener value="#{c}" target="#{colaboradorBean.colaborador}" />
                            </p:commandButton>
                        </p:column>
                        <p:column headerText="Excluir" >
                            <p:commandButton value="EXCLUIR" onclick="confirmation.show()">
                                <f:setPropertyActionListener value="#{c}" target="#{colaboradorBean.colaborador}" />
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>
                </p:panel>
                <p:confirmDialog modal="true" draggable="false" appendToBody="true" closable="true"
                                 message="Deseja realmente excluir este colaborador?" header="Aviso" widgetVar="confirmation" >
                    <p:commandButton id="btnSim" value="Sim" oncomplete="confirmation.hide();" actionListener="#{colaboradorBean.excluir}" process="@form" update="tabela" />

                    <p:commandButton value="Não" oncomplete="confirmation.hide()" />
                </p:confirmDialog>
            </h:form>


        </ui:define>
    </ui:decorate>
</html>
